<?php
$script = "
$('#change_password').change(function(){
    if (\$(this).attr('checked')) {
        $('#User_password').parents('.row').show();
        $('#User_confirmPassword').parents('.row').show();
    } else {
        $('#User_password').val('').parents('.row').hide();
        $('#User_confirmPassword').val('').parents('.row').hide();
    }
});
";
Yii::app()->clientScript->registerScript(__CLASS__ . '#ChangePassword', $script, CClientScript::POS_READY);
if ($model->isNewRecord == false)
    Yii::app()->clientScript->registerScript(__CLASS__ . '#HideChangePassword', "\$('#User_password').parents('.row').hide();\$('#User_confirmPassword').parents('.row').hide();", CClientScript::POS_READY);
if (Yii::app()->user->checkAccess(FAuthManager::ROLE_ADMINISTRATORS) && $model->id == Yii::app()->user->id)
    Yii::app()->clientScript->registerScript(__CLASS__ . '#DisableStatus', "\$('#User_status').parents('.row').hide();", CClientScript::POS_READY);
?>
<div class="form wide">

    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'user-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
    )
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php if (!$model->IsNewRecord) echo $form->hiddenField($model, "id"); ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'username'); ?>
        <?php echo $form->textField($model, 'username', array('size' => 60, 'maxlength' => 64)); ?>
        <?php echo $form->error($model, 'username'); ?>
    </div>

    <?php if ($model->isNewRecord == false): ?>
    <div class="row">
        <?php echo CHtml::label('Change Password', 'change_password'); ?>
        <?php echo CHtml::checkBox('change_password'); ?>
    </div>
    <?php endif;?>

    <div class="row">
        <?php echo $form->labelEx($model, 'password'); ?>
        <?php echo $form->passwordField($model, 'password', array('size' => 32, 'maxlength' => 32)); ?>
        <?php echo $form->error($model, 'password'); ?>
    </div>

    <div class="row">
        <label for="User_confirmPassword">Confirm new password</label>
        <?php echo $form->passwordField($model, 'confirmPassword', array('size' => 32, 'maxlength' => 32)); ?>
        <?php echo $form->error($model, 'confirmPassword'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'email'); ?>
        <?php echo $form->textField($model, 'email', array('size' => 60, 'maxlength' => 64)); ?>
        <?php echo $form->error($model, 'email'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->